﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Runtime.InteropServices;

namespace DMComputerInfo
{
    public partial class frmMain : Form
    {
        private string SysInfo;
        private string CPUInfo;
      
        public frmMain()
        {
            InitializeComponent();
            
        }
        private string DeviceInformation(string stringIn)
        {
            StringBuilder StringBuilder1 = new StringBuilder(string.Empty);
            ManagementClass ManagementClass1 = new ManagementClass(stringIn);
            //Create a ManagementObjectCollection to loop through
            ManagementObjectCollection ManagemenobjCol = ManagementClass1.GetInstances();
            //Get the properties in the class
            PropertyDataCollection properties = ManagementClass1.Properties;
            foreach (ManagementObject obj in ManagemenobjCol)
            {
                foreach (PropertyData property in properties)
                {
                    try
                    {
                        StringBuilder1.AppendLine(property.Name + ":  " +
                          obj.Properties[property.Name].Value.ToString());
                    }
                    catch
                    {
                        //Add codes to manage more informations
                    }
                }
                StringBuilder1.AppendLine();
            }
            return StringBuilder1.ToString();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            StringBuilder build=new StringBuilder(string.Empty);
            build.AppendFormat("Operation System kernel : {0} ", Environment.OSVersion.VersionString);
            if (Environment.Is64BitOperatingSystem == true)
            {
                build.AppendFormat("64 bit \n ");
            }
            else
            {
                build.AppendFormat("32 bit");
            }
            build.AppendFormat("System Directory: {0}\n", Environment.SystemDirectory);
            build.AppendFormat("Processor Count: {0} \n", Environment.ProcessorCount);
            build.AppendFormat("User Name {0}\n", Environment.UserName);
            build.AppendFormat("Logical drives:\n");
            foreach (var info in System.IO.DriveInfo.GetDrives())
            {
                build.AppendFormat("\t Drive: {0}\n\t\t VolumeLabel: " +
                                   "{1}\n\t\t DriveType: {2}\n\t\t DriveFormat: {3}\n\t\t " +
                                   "TotalSize: {4}\n\t\t AvailableFreeSpace: {5}\n",
                    info.Name, info.VolumeLabel, info.DriveType,
                    info.DriveFormat, info.TotalSize, info.AvailableFreeSpace);

            }
            build.AppendFormat("System page size: {0} \n", Environment.SystemPageSize);
            build.AppendFormat("Version {0}", Environment.Version);
            SysInfo = build.ToString();
            

        }

        private void tpSystem_Enter(object sender, EventArgs e)
        {
            lblCPU.Text = SysInfo;
        }

        private void tpVideo_Enter(object sender, EventArgs e)
        {
            lblVideo.Text = DeviceInformation("Win32_VideoController");
        }

     

        private void tpCPU_Enter(object sender, EventArgs e)
        {
           
            lblCPUInfo.Text = DeviceInformation("Win32_Processor");
        }

       

      

        private void tpBIOS_Enter(object sender, EventArgs e)
        {
            lblBIOS.Text = DeviceInformation("Win32_BIOS");
        }

        private void tpAbout_Enter(object sender, EventArgs e)
        {
          About about=new About();
            about.TopLevel = false;
            about.Visible = true;
            about.FormBorderStyle=FormBorderStyle.None;
            about.Dock=DockStyle.Fill;
            tpAbout.Controls.Add(about);
        }

        
        
       
    }
}
